<?php

namespace app\controller\mobile;

use app\common\model\Admin;
use app\common\model\Forum;
use app\common\model\User;
use app\common\service\IndexService;
use app\common\service\UserService;
use app\common\service\WechatXcxService;
use app\common\util\Result;
use think\annotation\route\Get;
use think\annotation\route\Group;
use think\annotation\route\Route;
use think\route\Domain;

#[Group('mobile/wechat_xcx')]
class WechatXcxController extends MobileAuthorizedController
{

    #[Get('login')]
    public function index()
    {
        $rule = [
            "code" => "require"
        ];
        $param = request()->param();
        $this->validate($param, $rule);
        $res = (new WechatXcxService(app()))->code2session($param);
        return Result::jsonByResult($res);
        //        var_dump($res);
        //$user = $this->getUserOrNull();
        // return Result::jsonByResult((new IndexService(app()))->index($user));

    }

    #[Get('unbind')]
    public function unbind(User $user)
    {
        $res = (new WechatXcxService(app()))->unbind($user);
        return Result::jsonByResult($res);
    }

    #[Route('GET|POST', "bind")]
    public function bind(User $user)
    {
        $rule = [
            "bind_key|绑定码" => "require",
            "user_wechat_id|微信用户ID" => "require"
        ];
        $param = request()->param();
        $this->validate($param, $rule);
        $res = (new WechatXcxService(app()))->bind($param, $user);
        return Result::jsonByResult($res);
    }

    //检测绑定情况
    #[Route('GET|POST', "check")]
    public function check(User $user)
    {
        return Result::jsonByResult((new WechatXcxService(app()))->checkBind($user));
    }


}
